<!-- left menu starts -->
<?php
use backend\service\ColumnService ;
use yii\helpers\Url ;
use yii\helpers\ArrayHelper ;
use backend\service\AuthService ;

$top_column_arr = ColumnService::findColumnList(null,1,0) ;

$top_column_arr = ColumnService::findColumnList(null,1,0) ;
$moduleNameArr = array_keys(Yii::$app->modules) ;

$username = Yii::$app->admin->identity->username ;
$user_id = Yii::$app->admin->identity->user_id ;
$new_column_list = [] ;
$auths = [] ;
if($username!="admin"){
    $controller_arr = AuthService::findItemChildByUserId($user_id) ;
    $top_column_list = $top_column_arr['list'] ;
    foreach($top_column_list as $val){
        if(in_array($val['tag'],$controller_arr)){
            $new_column_list[] = $val ;
        }
    }
    $auths = AuthService::findUserAuths($user_id) ;
}else{
    $new_column_list = $top_column_arr['list'];
}

$sub_column_arr = ColumnService::findColumnList(null,1,null,ColumnService::SUB_TYPE) ;
$sub_pid_arr = ArrayHelper::index($sub_column_arr['list'],null,"pid") ;

$module = \Yii::$app->controller->module->id;
/* 区分模块与action */
if($module =='app-backend'){
    $controller = Yii::$app->controller->id ;
    $controlleraction = Yii::$app->controller->action->id;
} else {
    $controller = $module;
    $controlleraction = Yii::$app->controller->id;
}

$icon_arr = [
    "fa-dashboard",
    "fa-laptop",
    "fa-th",
    "fa-files-o",
    "fa-cloud",
    "fa-dot-circle-o",
    "fa-life-ring",
    "fa-paw",
    "fa-gavel"
] ;
?>
<style type="text/css">
    .sidebar-menu .treeview-menu>li {
        border-bottom: 1px dashed #666;
        padding-top:6px;
        padding-bottom:6px;
        padding-left: 30px;
    }
</style>
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- Sidebar user panel -->
        <div class="user-panel">
            <div class="pull-left image">
                <img src="<?= \Yii::getAlias("@web")?>/dist/img/noavatar_big.gif" class="img-circle" alt="User Image" />
            </div>
            <div class="pull-left info">
                <p><?= Yii::$app->admin->identity->username?></p>
                <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
            </div>
        </div>
        <!-- /.search form -->
        <!-- sidebar menu: : style can be found in sidebar.less -->
        <ul class="sidebar-menu">
            <li class="header">导航</li>

            <?php foreach ($new_column_list as $key=>$value):?>
                <?php $active = ($controller==$value['tag'])?"active":""?>
                <li class="<?= $active?> treeview">

                    <?php $url = "/{$value['tag']}/index" ;?>
                    <?php if($value['tag']=="#"):?>
                        <?php $href = "#"?>
                    <?php else:?>
                        <?php $href =  Url::toRoute([$url])?>
                    <?php endif ;?>

                    <a href="<?=$href?>">
                        <?php $icon_base="fa-dot-circle-o"; ?>
                        <?php $icon = empty($icon_arr[$key])?$icon_base:$icon_arr[$key]?>
                        <i class="fa <?= $icon?>"></i>
                        <span><?= $value['name']?></span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>

                    <?php if(!empty($sub_pid_arr[$value['id']])):?>
                        <ul class="treeview-menu">
                            <?php $sub_columns = $sub_pid_arr[$value['id']] ;?>
                            <?php foreach ($sub_columns as $skey=>$svalue):?>
                                <?php $activeaction = ($controlleraction == $svalue['tag']) ? "actionactive" : "" ?>
                                <?php if(in_array($value['tag'],$moduleNameArr)):?>
                                    <?php $surl = "/{$value['tag']}/{$svalue['tag']}/index" ;?>
                                <?php else:?>
                                    <?php $surl = "/{$value['tag']}/{$svalue['tag']}" ;?>
                                <?php endif;?>
                                <?php $shref =  Url::toRoute([$surl])?>
                                <?php if($username!="admin"):?>
                                    <?php
                                    $authUrl = mb_substr($surl,1) ;
                                    if(in_array($authUrl,$auths)==false){
                                        continue ;
                                    }
                                    ?>
                                <?php endif;?>
                                <li><a class="<?= $activeaction ?>" href="<?=$shref?>"><span>></span>&nbsp;&nbsp;<?= $svalue['name']?></a></li>
                            <?php endforeach;?>
                        </ul>
                    <?php endif ;?>

                </li>
            <?php endforeach;?>
        </ul>
    </section>
    <!-- /.sidebar -->
</aside>